#!/bin/bash
# - testsuite
# - testcase

. $LKP_SRC/lib/upload.sh

dnf install -y git
git clone https://gitee.com/openeuler/mugen.git $TMP/mugen
cd $TMP/mugen

set_env()
{
	export LANG="en_US.UTF-8"
	bash dep_install.sh
	if [ -n "$direct_server_ips" ];then
		echo $(env | grep "direct")
		echo "direct_server_ips:$direct_server_ips, direct_client_1: $direct_client1_ips"
		bash mugen.sh -c --ip  $direct_server_ips --password $secrets_userpassword  --user $secrets_username --port 22 
		
		client_no=1
		while [ ! -z $(eval echo '${direct_client'"${client_no}"'_ips}') ];do
			direct_client_ips=$(eval echo '${direct_client'"${client_no}"'_ips}')
			bash mugen.sh -c --ip  $direct_client_ips --password $secrets_userpassword  --user $secrets_username --port 22
			{{ client_no++ }}
		done
	else
		direct_client_ips=$(ip addr show|grep inet|grep -v inet6|grep -Ewv "lo.*|docker.*|vlan.*|bond.*|virbr.*|br-.*" |awk '{print $2}'|awk -F "/" '{print $1}' |head -1)
		bash mugen.sh -c --ip  $direct_client_ips --password $secrets_userpassword  --user $secrets_username --port 22 
	fi
}

test_one_case()
{
	bash mugen.sh  -f "$testsuite" -r "$testcase" -x
}

test_one_testsuite()
{
	bash mugen.sh -f "$testsuite" -x
}

test_all_cases()
{
	bash mugen.sh -a -x
}

upload_logs()
{
       upload_files -t logs logs/*

}

run()
{
	set_env
	if [ -n "$testsuite" ];then
		if [ -n "$testcase" ];then
			test_one_case
		else
			test_one_testsuite
		fi
	else
		test_all_cases
	fi
	upload_logs
}

run
